import datetime
import sys
sys.path.append('C:/Project/Python3')
sys.path.append('D:/Project/Python3')
import Core.Gadget as Gadget
import Performance.FactorModel as FactorModel
import Strategy.Known4 as Known4
import Strategy.Known5 as Known5


from Core.Config import *
config = Config()
database = config.DataBase("Mongo")
realtime = config.RealTime()


# ---Current Time---
endDateTime = datetime.datetime.now()
if endDateTime.time() < datetime.time(15, 0, 0):
    endDateTime += datetime.timedelta(days=-1)
endDateTime = Gadget.ToDate(endDateTime)

# some times
monthBack = endDateTime + datetime.timedelta(days=-31)
quarterBack = endDateTime + datetime.timedelta(days=-92)
halfYearBack = endDateTime + datetime.timedelta(days=-183)
yearBack = endDateTime + datetime.timedelta(days=-365)
year2Back = endDateTime + datetime.timedelta(days=-365*2)
year3Back = endDateTime + datetime.timedelta(days=-365*3)


# Top Portfolio Analysis
# 发现最有效因子
dfPortfolio = FactorModel.Top100Portfolio(database, monthBack, endDateTime)
dfFactorModel = FactorModel.LoadModel(database, monthBack, endDateTime, factors={})
FactorModel.RegressToFactorModel(dfPortfolio, dfFactorModel)

# Factor Portfolio Test / Factor Significant
# 单因子测试
factors = []
FactorModel.LoadModel(database, monthBack, endDateTime)

# Known5 DayBreak1 第一模型
# 微观，基于Factor Model的高估低估
df = Known5.RunStrategy(endDateTime)

# Known4 DayBreak2 第二模型
# 微观，在可比较维度下的高估低估
reportDateTime = datetime(2019,3,31)
df = Known4.RunStrategy(reportDateTime)